<?php

namespace app\common\service\lib\sms;

class SmsRongLian
{
    /**
     * Author:Zhongyuan Lu
     * 容联云发送验证码
     * @param $to
     * @param $code int 验证码
     * @param int $tempId = 1
     * @return array
     */
    public function sendSms($to, $datas, $tempId = 1)
    {
        //主帐号
        $accountSid = config('setting.Sms.ronglian.accountSid');
        //主帐号Token
        $accountToken = config('setting.Sms.ronglian.accountToken');
        //应用Id
        $appId = config('setting.Sms.ronglian.appId');
        //请求地址，格式如下，不需要写https://,默认为：app.cloopen.com'
        $serverIP = 'app.cloopen.com';
        //请求端口 默认为：8883
        $serverPort = '8883';
        //REST版本号 默认为：2013-12-26
        $softVersion = '2013-12-26';
        //初始化REST SDK
        $rest = new SmsSDK($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);

        //发送模板短信
        $result = $rest->sendTemplateSMS($to, $datas, $tempId);
        if ($result == NULL) {
            return ['code' => 400, 'data' => [], 'message' => 'error'];
        }
        if ($result->statusCode != 0) {
            return ['code' => $result->statusCode, 'data' => [], 'message' => $result->statusMsg];
        } else {
            return ['code' => 200, 'data' => [], 'message' => '发送成功'];
        }
    }
}